﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace Pyramid_Game
{
    public abstract class GameAnimation
    {
        public Dictionary<string, Animation> animationCollection =
            new Dictionary<string, Animation>();
        public Rectangle drawRect;
        public string currentAnimation;
        public string newAnimation;

        public ScreenManager ScreenManager
        {
            get { return screenManager; }
            internal set { screenManager = value; }
        }

        ScreenManager screenManager;

        public void Initialize(Rectangle rect)
        {
            drawRect = rect;
        }
        public virtual void LoadContent(ContentManager content) { }
        public virtual void Update(Touch touch, GameTime gameTime) 
        {
            if (animationCollection.ContainsKey(currentAnimation))
            {
                if (animationCollection[currentAnimation].FinishedPlaying)
                {
                    PlayAnimation(animationCollection[currentAnimation].NextAnimation);
                }
                else
                {
                    animationCollection[currentAnimation].Update(gameTime);
                }
            }
        }
        public void PlayAnimation(string name)
        {
            if (!(name == null) && animationCollection.ContainsKey(name))
            {
                currentAnimation = name;
                animationCollection[name].Play();
            }
            else
            {
                screenManager.RemoveAnimation(this);
            }
        }
        public virtual void Draw(SpriteBatch spriteBatch) 
        {
            spriteBatch.Draw(
                    animationCollection[currentAnimation].Texture,
                    drawRect,
                    animationCollection[currentAnimation].FrameRectangle,
                    Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0f);
        }
    }
}
